﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ShopAdmin/Site.Master" AutoEventWireup="true" CodeBehind="LineAdd.aspx.cs" Inherits="VK.Casemeet.Web.ShopAdmin.Lines.LineAdd" %>

<asp:Content ID="Content1" ContentPlaceHolderID="contentHead" runat="server">
    <link rel="stylesheet" type="text/css" href="/Kindeditor/themes/default/default.css" />
    <link rel="stylesheet" type="text/css" href="/Kindeditor/plugins/code/prettify.css" />
    <script type="text/javascript" charset="utf-8" src="/Kindeditor/kindeditor-min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/Kindeditor/lang/zh_CN.js"></script>
    <script type="text/javascript" charset="utf-8" src="/Kindeditor/plugins/code/prettify.js"></script>
    <script type="text/javascript" src="/Scripts/ajaxupload.js"></script>
    <script type="text/javascript">
        function butsubmit() {
            if (validator.form()) {
                //图片
                var imgUrlArray = new Array();
                $("#imgArea img").each(function (i) {
                    imgUrlArray[i] = $(this).attr("src").replace('/UserImages/Lines/', '');
                });
                $("#hidImgUrlArray").val(JSON.stringify(imgUrlArray));
                //出发日期
                var scheduleArray = new Array();
                $("#divSchedule .item").each(function (i) {
                    scheduleArray[scheduleArray.length] = new LineScheduleEntity(0, 0,
                        $(this).find(".departure").html());
                });
                $("#hidScheduleArray").val(JSON.stringify(scheduleArray));
                if (scheduleArray.length > 0) {
                    return true;
                } else {
                    alert("请填写出发日期");
                    return false;
                }
            } else {
                return false;
            }
        }
    </script>
    <script type="text/javascript">
        function AddItem(sender) {
            var temphtml = new String;
            if ($("#txtDeparture").val() != "") {
                temphtml = "<div class='item'>" +
                   "     <div class='departure'>" + $("#txtDeparture").val() + "</div>" +
                   "     <div class='oper'>" +
                   "         <div class='right tableOperDelete' onclick='DeleteItem(this);'>&nbsp;</div>" +
                   "     </div>" +
                   " </div>";
                $(sender).parent().before(temphtml);
            }
            $("#txtDeparture").val("");
            $("#txtClosing").val("");
        }

        function DeleteItem(sender) {
            $(sender).parent().parent().remove();
        }

        function LineScheduleEntity(scheduleID, lineID, departureDate, closingDate) {
            this.ScheduleID = scheduleID;
            this.LineID = lineID;
            this.DepartureDate = departureDate;
            this.ClosingDate = closingDate;
        }
    </script>
    <script type="text/javascript">
        KindEditor.ready(function (K) {
            var editor1 = K.create('#txtLineFeatures', {
                cssPath: '/Kindeditor/plugins/code/prettify.css',
                uploadJson: '/PageHandler/UploadJson.ashx',
                fileManagerJson: '/PageHandler/FileManagerJson.ashx',
                resizeType: 1,
                allowFileManager: false,
                allowImageUpload: false,
                items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'link'],
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    $('.butSave').click(function () {
                        self.sync();
                    });
                }
            });
            var editor2 = K.create('#txtReferenceStroke', {
                cssPath: '/Kindeditor/plugins/code/prettify.css',
                uploadJson: '/PageHandler/UploadJson.ashx',
                fileManagerJson: '/PageHandler/FileManagerJson.ashx',
                resizeType: 1,
                allowFileManager: false,
                allowImageUpload: false,
                items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'link'],
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    $('.butSave').click(function () {
                        self.sync();
                    });
                }
            });
            var editor3 = K.create('#txtCostDescription', {
                cssPath: '/Kindeditor/plugins/code/prettify.css',
                uploadJson: '/PageHandler/UploadJson.ashx',
                fileManagerJson: '/PageHandler/FileManagerJson.ashx',
                resizeType: 1,
                allowFileManager: false,
                allowImageUpload: false,
                items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'link'],
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    $('.butSave').click(function () {
                        self.sync();
                    });
                }
            });
            var editor4 = K.create('#txtPrecautions', {
                cssPath: '/Kindeditor/plugins/code/prettify.css',
                uploadJson: '/PageHandler/UploadJson.ashx',
                fileManagerJson: '/PageHandler/FileManagerJson.ashx',
                resizeType: 1,
                allowFileManager: false,
                allowImageUpload: false,
                items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'link'],
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                        K('form[id=mainForm]')[0].submit();
                    });
                    $('.butSave').click(function () {
                        self.sync();
                    });
                }
            });
            prettyPrint();
        });

        $("document").ready(function () {
            if (<% =destinationArea1 %> == 0) {
                BindDestinationArea(0, "#ddlDestinationArea1", 0, 0, 0);
            } else {
                BindDestinationArea(0, "#ddlDestinationArea1", <% =destinationArea1 %>, <% =destinationArea2 %>, <% =destinationArea3 %>);
            }
            if (<% =stagingArea1 %> == 0) {
                BindStagingArea(0, "#ddlStagingArea1", 0, 0, 0);
            } else {
                BindStagingArea(0, "#ddlStagingArea1", <% =stagingArea1 %>, <% =stagingArea2 %>, <% =stagingArea3 %>);
            }
        });

        function BindDestinationArea(parentID, ddlControl, area1, area2, area3) {
            $.ajax({
                type: "post",
                url: "/Admin/CommService.asmx/GetArea",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                data: "{ \"parentID\":" + parentID + " }",
                beforeSend: function (jsonHttpRequest) {
                    this;
                },
                success: function (jsonHttpRequest, textStatus) {
                    var temp_option = new String;
                    temp_option += "<option value=\"0\">请选择</option>";
                    if (ddlControl == "#ddlDestinationArea1") { temp_option = fillOption(temp_option, jsonHttpRequest, area1); }
                    if (ddlControl == "#ddlDestinationArea2" && parentID != "0") { temp_option = fillOption(temp_option, jsonHttpRequest, area2); }
                    if (ddlControl == "#ddlDestinationArea3" && parentID != "0") { temp_option = fillOption(temp_option, jsonHttpRequest, area3); }
                    $(ddlControl).html(temp_option);
                    if (ddlControl == "#ddlDestinationArea1") {
                        BindDestinationArea($(ddlControl).val(), "#ddlDestinationArea2", area1, area2, area3);
                    }
                    if (ddlControl == "#ddlDestinationArea2") {
                        BindDestinationArea($(ddlControl).val(), "#ddlDestinationArea3", area1, area2, area3);
                    }
                },
                error: function (jsonHttpRequest, textStatus, errorThrown) {
                    this;
                },
                complete: function (jsonHttpRequest, textStatus) {
                    this;
                }
            });
        }
        function destinationArea1_onchange() {
            if ($("#ddlDestinationArea1").val() != "0") {
                $("#ddlDestinationArea2").html("");
                BindDestinationArea($("#ddlDestinationArea1").val(), "#ddlDestinationArea2", 0, 0, 0);
            }
        }
        function destinationArea2_onchange() {
            if ($("#ddlDestinationArea2").val() != "0") {
                $("#ddlDestinationArea3").html("");
                BindDestinationArea($("#ddlDestinationArea2").val(), "#ddlDestinationArea3", 0, 0, 0);
            }
        }
        function destinationArea3_onchange() {
            
        }
        function fillOption(temp_option, jsonHttpRequest, area) {
            $.each(jsonHttpRequest.d, function (i, field) {
                if (area == field.AreaID) {
                    temp_option += "<option selected value=\"" + field.AreaID + "\">" + field.Name + "</option>";
                } else {
                    temp_option += "<option value=\"" + field.AreaID + "\">" + field.Name + "</option>";
                }
            });
            return temp_option;
        }

        function BindStagingArea(parentID, ddlControl, area1, area2, area3) {
            $.ajax({
                type: "post",
                url: "/Admin/CommService.asmx/GetArea",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                data: "{ \"parentID\":" + parentID + " }",
                beforeSend: function (jsonHttpRequest) {
                    this;
                },
                success: function (jsonHttpRequest, textStatus) {
                    var temp_option = new String;
                    temp_option += "<option value=\"0\">请选择</option>";
                    if (ddlControl == "#ddlStagingArea1") { temp_option = fillOption(temp_option, jsonHttpRequest, area1); }
                    if (ddlControl == "#ddlStagingArea2" && parentID != "0") { temp_option = fillOption(temp_option, jsonHttpRequest, area2); }
                    if (ddlControl == "#ddlStagingArea3" && parentID != "0") { temp_option = fillOption(temp_option, jsonHttpRequest, area3); }
                    $(ddlControl).html(temp_option);
                    if (ddlControl == "#ddlStagingArea1") {
                        BindStagingArea($(ddlControl).val(), "#ddlStagingArea2", area1, area2, area3);
                    }
                    if (ddlControl == "#ddlStagingArea2") {
                        BindStagingArea($(ddlControl).val(), "#ddlStagingArea3", area1, area2, area3);
                    }
                },
                error: function (jsonHttpRequest, textStatus, errorThrown) {
                    this;
                },
                complete: function (jsonHttpRequest, textStatus) {
                    this;
                }
            });
        }
        function stagingArea1_onchange() {
            if ($("#ddlStagingArea1").val() != "0") {
                $("#ddlStagingArea2").html("");
                BindStagingArea($("#ddlStagingArea1").val(), "#ddlStagingArea2", 0, 0, 0);
            }
        }
        function stagingArea2_onchange() {
            if ($("#ddlStagingArea2").val() != "0") {
                $("#ddlStagingArea3").html("");
                BindStagingArea($("#ddlStagingArea2").val(), "#ddlStagingArea3", 0, 0, 0);
            }
        }
        function stagingArea3_onchange() {
            
        }


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentBody" runat="server">
    <div class="bodyContent divBody">
        <div class="divDetailOper">
            <asp:LinkButton ID="butSave" runat="server" CssClass="butSave" onclick="butSave_Click" OnClientClick="return butsubmit()">保存信息</asp:LinkButton>
            <a class="butBack" href="LineList.aspx">返回列表</a>
        </div>
        <div class="left" style="width:74%;margin:10px 0 0 1%;_margin:10px 0 0 0.5%;height:auto;">
            <div class="divEdit" style="width:100%;">
                <div class="title">基本信息</div>
                <div class="content">
                    <table cellpadding="0" cellspacing="0" class="tableLeftEdit">
                    <tbody>
                        <tr>
                            <th>名称：</th>
                            <td><asp:TextBox ID="txtName" runat="server" CssClass="inputText required" Width="80%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>目的地：</th>
                            <td>
                                <select id="ddlDestinationArea1" name="ddlDestinationArea1" onchange="destinationArea1_onchange();" class="selectddl {min:1, messages:{min:'请选择一项'}}" style="width:auto;"></select>
		                        <select id="ddlDestinationArea2" name="ddlDestinationArea2" onchange="destinationArea2_onchange();" class="selectddl {min:1, messages:{min:'请选择一项'}}" style="width:auto;"></select>
		                        <select id="ddlDestinationArea3" name="ddlDestinationArea3" onchange="destinationArea3_onchange();" class="selectddl" style="width:auto;"></select>
                            </td>
                        </tr>
                        <tr>
                            <th>集结地：</th>
                            <td>
                                <select id="ddlStagingArea1" name="ddlStagingArea1" onchange="stagingArea1_onchange();" class="selectddl {min:1, messages:{min:'请选择一项'}}" style="width:auto;"></select>
		                        <select id="ddlStagingArea2" name="ddlStagingArea2" onchange="stagingArea2_onchange();" class="selectddl {min:1, messages:{min:'请选择一项'}}" style="width:auto;"></select>
		                        <select id="ddlStagingArea3" name="ddlStagingArea3" onchange="stagingArea3_onchange();" class="selectddl" style="width:auto;"></select>
                            </td>
                        </tr>
                        <tr>
                            <th>活动类型：</th>
                            <td><asp:DropDownList ID="ddlType" runat="server" CssClass="selectddl {min:1, messages:{min:'请选择一项'}}"></asp:DropDownList></td>
                        </tr>
                        <tr>
                            <th>活动时长：</th>
                            <td><asp:TextBox ID="txtDays" runat="server" CssClass="inputText required number" Width="30%"></asp:TextBox>天</td>
                        </tr>
                        <tr>
                            <th>节日：</th>
                            <td><asp:DropDownList ID="ddlHoliday" runat="server" CssClass="selectddl"></asp:DropDownList></td>
                        </tr>
                        <tr>
                            <th>住宿方式：</th>
                            <td><asp:DropDownList ID="ddlStay" runat="server" CssClass="selectddl {min:1, messages:{min:'请选择一项'}}"></asp:DropDownList></td>
                        </tr>
                        <tr>
                            <th>活动分级：</th>
                            <td><asp:DropDownList ID="ddlGrade" runat="server" CssClass="selectddl {min:1, messages:{min:'请选择一项'}}"></asp:DropDownList></td>
                        </tr>
                        <tr>
                            <th>预计费用：</th>
                            <td><asp:TextBox ID="txtPrice" runat="server" CssClass="inputText required number" Width="30%"></asp:TextBox>元</td>
                        </tr>
                        <tr>
                            <th>线路特色：</th>
                            <td><textarea id="txtLineFeatures" name="txtLineFeatures" style="width:100%;height:350px;"><% =lineFeatures %></textarea></td>
                        </tr>
                        <tr>
                            <th>参考行程：</th>
                            <td><textarea id="txtReferenceStroke" name="txtReferenceStroke" style="width:100%;height:350px;"><% =referenceStroke %></textarea></td>
                        </tr>
                        <tr>
                            <th>费用说明：</th>
                            <td><textarea id="txtCostDescription" name="txtCostDescription" style="width:100%;height:200px;"><% =costDescription%></textarea></td>
                        </tr>
                        <tr>
                            <th>注意事项：</th>
                            <td><textarea id="txtPrecautions" name="txtPrecautions" style="width:100%;height:200px;"><% =precautions %></textarea></td>
                        </tr>
                    </tbody>
                    </table>
                </div>
            </div>
            <div class="divEdit martop10" style="width:100%;padding-bottom:20px;">
                <div class="title">
                    <p class="contenta">线路图片</p>
                    <p class="contentb"><span class="padlef20" style="color:Red;"></span><a href="#" id="butImgUrl" style="color:#1d3d83;">【点我上传图片】</a></p>
                    <input id="hidImgUrlArray" name="hidImgUrlArray" type="hidden" value='<% =imgUrl %>' />
                    <script type="text/javascript">
                        $(document).ready(function() {
                            var button = $('#butImgUrl'), interval;
                            new AjaxUpload(button, {
                                action: '',
                                onSubmit: function (file, ext) {
                                    if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                                        alert('错误:图片格式不正确!');
                                        return false;
                                    }
                                    if ($("#imgArea").children("div").length >= 10) {
                                        alert('图片上传限制10张');
                                        return false;
                                    }
                                    this._settings.action = '/PageHandler/UpLoadFile.ashx?folderName=Lines/';
                                    this._settings.data = { oldFileName: $('#divImgUrl img').attr('src') };
                                    this.disable();
                                    var tips = $("#butImgUrl").prev();
                                    tips.html("文件上传中请等待");
                                    interval = window.setInterval(function () {
                                        if (tips.html().length < 20) {
                                            tips.html(tips.html() + ">");
                                        } else {
                                            tips.html('文件上传中请等待');
                                        }
                                    }, 300);
                                },
                                onComplete: function (file, response) {
                                    $("#butImgUrl").prev().html('');
                                    window.clearInterval(interval);
                                    this.enable();
                                    window.clearInterval(interval);
                                    var jsondata = JSON.parse(response);
                                    if (jsondata.Error.length == 0) {
                                        $("#imgArea").append("<div style='float:left;width:145px;height:130px;border:1px solid #eaeaea;background:#f5f5f5;margin:10px 0 0 10px;'>" +
                                        "<img alt='' src='/UserImages/Lines/" + jsondata.FileName + "' style='width:139px;height:100px;padding:3px;'/>" +
                                        "<p class='sj10 hg22 txtlef hand' onclick='$(this).parent().remove()'>删除</p></div>");
                                    } else {
                                        alert(jsondata.Error);
                                    }
                                }
                            });
                        });
                    </script>
                </div>
                <div id="imgArea" class="content">
                    
                </div>
            </div>
        </div>
        <div class="left" style="width:23%;margin:10px 0 0 1%;_margin:10px 0 0 0.5%;height:auto;">
            <div class="divEdit" style="width:100%;">
                <div class="title">系统信息</div>
                <div class="content">
                    <table cellpadding="0" cellspacing="0" class="tableRightEdit">
                        <tbody>
                            <tr><th>编辑人：</th></tr>
                            <tr><td><asp:Label ID="lbEditor" runat="server" Text="管理员"></asp:Label></td></tr>
                            <tr><th>创建时间：</th></tr>
                            <tr><td><asp:TextBox ID="txtCreated" runat="server" CssClass="inputText" Width="80%" onclick="return showCalendar(this.id, 'y-m-d');"></asp:TextBox></td></tr>
                            <tr><th>点击：</th></tr>
                            <tr><td><asp:TextBox ID="txtHits" runat="server" CssClass="inputText digits" Width="80%" Text="0" ReadOnly="True"></asp:TextBox></td></tr>
                         </tbody>
                    </table>
                </div>
            </div>
            <div class="divEdit martop10" style="width:100%;">
                <div class="title">出发时间</div>
                <div id="divSchedule" class="content lineSchedule">
                    <div style="background-color:#f0f8ff;height:28px;line-height:28px;">
                        <p class="left" style="width:70%">出发日期</p>
                    </div>
                    <div class="clear" style="padding:8px 5px 0 10px;background-color:#f1f7f7;height:30px;margin:5px 0px 0 0px;">
                        <input id="txtDeparture" name="txtDeparture" type="text" class="left inputText txtcen" style="width:70%" onclick="return showCalendar(this.id, 'y-m-d');" />
                        <div class='left tableOperNew' onclick='AddItem(this);'>&nbsp;添加</div>
                    </div>
                </div>
                <input id="hidScheduleArray" name="hidScheduleArray" type="hidden" />
            </div>
        </div>
        <div class="clear f0" style="height:10px; width:100%"></div>
        <div class="clear divDetailOper">
            <asp:LinkButton ID="LinkButton1" runat="server" CssClass="butSave" onclick="butSave_Click" OnClientClick="return butsubmit()">保存信息</asp:LinkButton>
            <a class="butBack" href="LineList.aspx">返回列表</a>
        </div>
        <div class="clear f0" style="height:20px; width:100%"></div>
    </div>
</asp:Content>
